{[ template "__start__.html" . ]}
<body>
<div id="app">
    {[ template "__header__.html" . ]}
    <div class="container-fluid">
        <div class="row">
            {[ template "__menu__.html" . ]}
            <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">

                上传包:
                <div class="form-floating">
                    <input type="file" class="form-control" id="uploadFile" placeholder="name">
                    <label for="uploadFile">上传安卓包(默认下载地址: {[ .download ]} )</label>
                </div>
                <br>
                <div class="form-floating">
                    <button type="button" class="btn btn-primary" @click="upload()">上传包</button>
                </div>

                <br>
                <br>
                <hr>
                <br>

                游戏设置:
                <div class="form-floating">
                    <input type="text" class="form-control" id="apk_download" v-model="apk_version"  placeholder="name">
                    <label for="apk_download">游戏版本(安卓包版本)</label>
                </div>
                <br>
                <div class="form-floating">
                    <input type="text" class="form-control" id="apk_version" v-model="apk_download" placeholder="name">
                    <label for="apk_version">游戏下载地址(安卓包)</label>
                </div>
                <br>
                <div class="form-floating">
                    <input type="text" class="form-control" id="ios_version" v-model="ios_version"  placeholder="name">
                    <label for="ios_version">游戏版本(IOS包版本)</label>
                </div>
                <br>
                <div class="form-floating">
                    <input type="text" class="form-control" id="ios_download" v-model="ios_download" placeholder="name">
                    <label for="ios_download">游戏下载地址(IOS包)</label>
                </div>
                <br>
                <div class="form-floating">
                    <input type="text" class="form-control" id="notice" v-model="notice" placeholder="name">
                    <label for="notice">公告</label>
                </div>
                <br>

                <div class="form-floating">
                    <button type="button" class="btn btn-primary" @click="update()">保存</button>
                </div>

                {[ template "__toast__.html" . ]}
            </main>
        </div>
    </div>
</div>
</body>
{[ template "__js__.html" . ]}
<script>
    const { createApp, ref } = Vue;
    const common = new Utils;
    const app = createApp({
        data() {
            return {
                apk_download: "",
                apk_version: "",
                ios_download: "",
                ios_version: "",
                notice: "",
            }
        },
        created:function(){
            let t = this;
            t.getConf();
        },
        destroyed:function () {
        },
        methods: {
            getConf: function () {
                let t = this;
                common.AjaxGet("/admin/conf/info", function (resp) {
                    console.log(resp);
                    t.apk_download = resp.data.apk_download;
                    t.apk_version = resp.data.apk_version;
                    t.ios_download = resp.data.ios_download;
                    t.ios_version = resp.data.ios_version;
                    t.notice = resp.data.notice;
                });
            },

            update: function () {
                let t = this;

                let param = {
                    "apk_download" : t.apk_download,
                    "apk_version" : t.apk_version,
                    "ios_download" : t.ios_download,
                    "ios_version" : t.ios_version,
                    "notice" : t.notice
                }
                common.AjaxPost("/admin/conf/update", param, function (resp) {
                    console.log(resp);
                    common.ToastShow("保存成功")
                });

            },

            upload: function () {
                let t = this;

                var file = document.getElementById('uploadFile').files[0]; //获取选中的文件对象

                var formData = new FormData(); //创建FormData对象
                formData.append("apk", file); //将文件添加到formData中

                common.ToastShow("文件上传中,请勿关闭页面!")

                $.ajax({
                    url: "/admin/add/apk", //设置上传文件的URL地址
                    method: 'post', //指定HTTP请求类型为POST
                    dataType: 'json', //期望返回JSON格式的结果
                    processData: false, //不处理发送的数据（必须）
                    contentType: false, //不设置Content-Type头信息（必须）
                    data: formData, //将表单数据作为参数传入

                    success: function(response){
                        console.log(response); //打印成功后的返回结果
                        common.ToastShow("文件上传成功!");

                        t.apk_download = response.data;

                    },
                    error: function(xhr, status, error){
                        console.error(status + ": " + error); //打印错误信息
                        common.ToastShow("文件上传失败, "+ error);
                    }
                });

            },


        },
        computed: {
        },
        mounted:function(){
        },
    });
    app.mount('#app');
</script>
{[ template "__end__.html" . ]}